package com.zsy.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zsy.bean.Keyword;
import com.zsy.service.BBSService;

public class AllKeywords extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession sess = req.getSession();
		try {
			String type = req.getParameter("type");
			String page = req.getParameter("page");
			if(null == page||(null!=page&&Integer.parseInt(page)<=0)){
				page="1";
			}
			BBSService bbss = new BBSService();
			List<Keyword> keylist = bbss.showAllKeyword(Integer.parseInt(type), Integer
					.parseInt(page));
			sess.setAttribute("pk", page);
			sess.setAttribute("keylist", keylist);
			if ("0".equals(type)) {
				sess.setAttribute("type", 0);
				resp.sendRedirect(req.getContextPath()+"/web/keywordManager.jsp");
			} else {
				sess.setAttribute("type", 1);
				resp.sendRedirect(req.getContextPath()+"/web/keywordManager.jsp");
			}
		} catch (SQLException e) {
			sess.setAttribute("msg", "关键字已经存在，无需重复添加！");
		}
	}


}
